package com.piggy.logi.sys.api.factory;

import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.logi.sys.api.domain.LogiSysUser;
import com.piggy.logi.sys.api.RemoteLogiUserService;
import com.piggy.common.core.domain.R;
import com.piggy.sys.api.domain.SysUser;
import com.piggy.sys.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理98
 *
 * @author shark
 */
@Component
public class RemoteLogiUserFallbackFactory implements FallbackFactory<RemoteLogiUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteLogiUserFallbackFactory.class);

    @Override
    public RemoteLogiUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteLogiUserService()
        {
            @Override
            public R<LoginUser<LogiSysUser>> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser<LogiSysUser>> getUserByPhone(String username, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser<LogiSysUser>> getUserByEmail(String username, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LogiSysUser> getSysUser(String username, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LogiSysUser> register(LogiSysUser logiSysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LogiSysUser> getInfo(Long userId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<LogiSysUser>> getUserByDeptId(Long deptId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<LogiSysUser>> getUserByDeptIds(List<Long> deptIds, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<LogiSysUser>> queryUserAll(Long mainDeptId, String source) {
                return null;
            }

            @Override
            public R<List<LogiSysUser>> getUsersByPhoneNumber(String phoneNumber, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LogiSysUser> getUserByID(String userId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public TableDataInfo<LogiSysUser> innerList(LogiSysUser user, String source) {
                return TableDataInfo.buildFail(-1, "获取用户列表失败");
            }

            @Override
            public R<LoginUser<LogiSysUser>> getUserInfoByDept(String username, String deptId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser<LogiSysUser>> getUserByPhoneByDept(String phone, String deptId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser<LogiSysUser>> getUserByEmailByDept(String email, String deptId, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R bossAdd(LogiSysUser user, String source) {
                return R.fail("新增用户部门失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> resetPwd(String phone, String dept, String passwd, String source) {
                return R.fail("服务调用失败");
            }

            @Override
            public R<Integer> resetMainUserPwd(String phone, String passwd, String source) {
                return R.fail("服务调用失败");
            }

            @Override
            public R<LogiSysUser> getMainUser(String phone, String source) {
                return R.fail("服务调用失败");
            }
        };
    }
}
